#coding=utf-8
import os
import time

class BasePage(object):
    '''
    将常用的几个selenium方法封装到basepage这个类中
    '''
    def __init__(self,driver):
        '''
        写一个构造函数，有一个参数driver
        :param driver:
        :return:
        '''
        self.driver = driver
    def back(self):
        '''
        浏览器后退按钮
        :return:
        '''
        self.driver.back()
    def forward(self):
        self.driver.forward()

    def quit_browser(self):
        self.driver.quit()

    def open_url(self,urlPath):
        self.driver.get(urlPath)

    def take_screenshot(self):
        '''
        截图并保存在根目录下的screenshots文件夹下
        :return:
        '''
        file_path = os.path.dirname(os.getcwd())+'/screenshots/'
        rq = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
        screeen_name = file_path+rq+'.png'
        try:
            self.driver.get_screenshot_as_file(screeen_name)
            print('截图并保存',"路径为：",file_path)
        except Exception as e:
            print(format(e))